import java.util.Arrays;

public class Work {
    public static void main5(String[] args) {
        //求1/1-1/2+1/3...-1/100的和
        double ret = sum2();
        System.out.println(ret);
    }
    public static double sum2(){
        double sum=0.0;
        int flag=1;
        for(int i=1;i<101;i++) {
            sum=sum+flag*1*1.0/i;
            flag=-flag;
        }
        return sum;
    }


    public static void main4(String[] args) {
        //数组的平均值
        int[] array=new int[]{1,2,3};
        double ret = avg(array);
        System.out.println(ret);
    }
    public static double avg(int[] array) {
        double sum=0.0;
        for(int i=0;i<array.length;i++) {
            sum+=array[i];
        }
        return sum/ array.length;
    }


    public static void main3(String[] args) {
        //数组所有元素之和
        int[] array=new int[]{1,2,3};
        int ret=sum(array);
        System.out.println(ret);
    }

    public static int sum(int[] array) {
        int sum=0;
        for(int i=0;i<array.length;i++) {
            sum+=array[i];
        }
        return sum;
    }


    public static void main2(String[] args) {
        //把数组中的值扩大2倍
        int[] array=new int[]{1,2,3};
        towMax(array);
        System.out.println(Arrays.toString(array));
    }

    public static void towMax(int[] array) {
        for(int i=0;i<array.length;i++) {
            array[i]=array[i]*2;
        }
    }

    public static void main1(String[] args) {
    //创建一个数组存放1--100并打印
        int[] array =new int[100];
        for(int i=0;i<array.length;i++){
            array[i]=i+1;
        }
        System.out.println(Arrays.toString(array));
    }
}
